Changing comments layout preparing for generated documentation with Phpdocumentor
[lhc/web/wiklou.git] / includes / PageHistory.php
1 <?php
2 /**
3 * Page history
4 *
5 * Split off from Article.php and Skin.php, 2003-12-22
6 */
7
8 /**
9 * @todo document
10 */
11 class PageHistory {
12 var $mArticle, $mTitle, $mSkin;
13 var $lastline, $lastdate;
14 var $linesonpage;
15 function PageHistory( $article ) {
16 $this->mArticle =& $article;
17 $this->mTitle =& $article->mTitle;
18 }
19
20 # This shares a lot of issues (and code) with Recent Changes
21
22 function history() {
23 global $wgUser, $wgOut, $wgLang;
24
25 # If page hasn't changed, client can cache this
26
27 if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
28 # Client cache fresh and headers sent, nothing more to do.
29 return;
30 }
31 $fname = 'PageHistory::history';
32 wfProfileIn( $fname );
33
34 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
35 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
36 $wgOut->setArticleFlag( false );
37 $wgOut->setArticleRelated( true );
38 $wgOut->setRobotpolicy( 'noindex,nofollow' );
39
40 if( $this->mTitle->getArticleID() == 0 ) {
41 $wgOut->addHTML( wfMsg( 'nohistory' ) );
42 wfProfileOut( $fname );
43 return;
44 }
45
46 list( $limit, $offset ) = wfCheckLimits();
47
48 /* We have to draw the latest revision from 'cur' */
49 $rawlimit = $limit;
50 $rawoffset = $offset - 1;
51 if( 0 == $offset ) {
52 $rawlimit--;
53 $rawoffset = 0;
54 }
55 /* Check one extra row to see whether we need to show 'next' and diff links */
56 $limitplus = $rawlimit + 1;
57
58 $namespace = $this->mTitle->getNamespace();
59 $title = $this->mTitle->getText();
60
61 $db =& wfGetDB( DB_SLAVE );
62 $use_index = $db->useIndexClause( 'name_title_timestamp' );
63 $oldtable = $db->tableName( 'old' );
64
65 $sql = "SELECT old_id,old_user," .
66 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
67 "FROM $oldtable $use_index " .
68 "WHERE old_namespace={$namespace} AND " .
69 "old_title='" . $db->strencode( $this->mTitle->getDBkey() ) . "' " .
70 "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
71 $res = $db->query( $sql, $fname );
72
73 $revs = $db->numRows( $res );
74
75 if( $revs < $limitplus ) // the sql above tries to fetch one extra
76 $this->linesonpage = $revs;
77 else
78 $this->linesonpage = $revs - 1;
79
80 $atend = ($revs < $limitplus);
81
82 $this->mSkin = $wgUser->getSkin();
83 $numbar = wfViewPrevNext(
84 $offset, $limit,
85 $this->mTitle->getPrefixedText(),
86 'action=history', $atend );
87 $s = $numbar;
88 if($this->linesonpage > 0) {
89 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
90 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
91 $this->submitbuttonhtml1 = $submitpart1 . ' />';
92 $this->submitbuttonhtml2 = $submitpart1 . ' id="historysubmit" />';
93 }
94 $s .= $this->beginHistoryList();
95 $counter = 1;
96 if( $offset == 0 ){
97 $this->linesonpage++;
98 $s .= $this->historyLine(
99 $this->mArticle->getTimestamp(),
100 $this->mArticle->getUser(),
101 $this->mArticle->getUserText(), $namespace,
102 $title, 0, $this->mArticle->getComment(),
103 ( $this->mArticle->getMinorEdit() > 0 ),
104 $counter++
105 );
106 }
107 while ( $line = $db->fetchObject( $res ) ) {
108 $s .= $this->historyLine(
109 $line->old_timestamp, $line->old_user,
110 $line->old_user_text, $namespace,
111 $title, $line->old_id,
112 $line->old_comment, ( $line->old_minor_edit > 0 ),
113 $counter++
114 );
115 }
116 $s .= $this->endHistoryList( !$atend );
117 $s .= $numbar;
118 $wgOut->addHTML( $s );
119 wfProfileOut( $fname );
120 }
121
122 function beginHistoryList() {
123 global $wgTitle;
124 $this->lastdate = $this->lastline = '';
125 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
126 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
127 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
128 $s .= "<input type='hidden' name='title' value='{$prefixedkey}' />\n";
129 $s .= !empty($this->submitbuttonhtml1) ? $this->submitbuttonhtml1."\n":'';
130 $s .= '<ul id="pagehistory">';
131 return $s;
132 }
133
134 function endHistoryList( $skip = false ) {
135 $last = wfMsg( 'last' );
136
137 $s = $skip ? '' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
138 $s .= '</ul>';
139 $s .= !empty($this->submitbuttonhtml2) ? $this->submitbuttonhtml2 : '';
140 $s .= '</form>';
141 return $s;
142 }
143
144 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' ) {
145 global $wgLang;
146
147 $artname = Title::makeName( $ns, $ttl );
148 $last = wfMsg( 'last' );
149 $cur = wfMsg( 'cur' );
150 $cr = wfMsg( 'currentrev' );
151
152 if ( $oid && $this->lastline ) {
153 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
154 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline );
155 } else {
156 $ret = '';
157 }
158 $dt = $wgLang->timeanddate( $ts, true );
159
160 if ( $oid ) {
161 $q = 'oldid='.$oid;
162 } else {
163 $q = '';
164 }
165 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
166
167 if ( 0 == $u ) {
168 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( 'Contributions' ),
169 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
170 } else {
171 $ul = $this->mSkin->makeLink( $wgLang->getNsText(
172 Namespace::getUser() ) . ':'.$ut , htmlspecialchars( $ut ) );
173 }
174
175 $s = '<li>';
176 if ( $oid ) {
177 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
178 'diff=0&oldid='.$oid );
179 } else {
180 $curlink = $cur;
181 }
182 $arbitrary = '';
183 if( $this->linesonpage > 1) {
184 # XXX: move title texts to javascript
185 $checkmark = '';
186 if ( !$oid ) {
187 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
188 $checkmark = ' checked="checked"';
189 } else {
190 if( $counter == 2 ) $checkmark = ' checked="checked"';
191 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
192 $checkmark = '';
193 }
194 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
195 }
196 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
197 $s .= $isminor ? ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
198
199
200 if ( '' != $c && '*' != $c ) {
201 $c = $this->mSkin->formatcomment($c,$this->mTitle);
202 $s .= " <em>($c)</em>";
203 }
204 $s .= '</li>';
205
206 $this->lastline = $s;
207 return $ret;
208 }
209
210 }
211
212 ?>